package any.incubator;

import java.util.Iterator;
import java.util.Map.Entry;

import any.Any;
import any.AnyVisitor;
import any.ImmutableAny;
import any.SequentialAny;
import any.functor.interfaces.Function;
import any.impl.util.EntriesIterableAdapter;

public abstract class BaseSequentialAny implements SequentialAny {

	public <T> T give(Function<? super SequentialAny, T> func) throws NullPointerException {
		return func.apply(this);
	}
	
	public ImmutableAny toImmutable() {
		return toAny(false);
	}

	public Any toMutable() {
		return toAny(true);
	}

	public Any toAny() {
		return toAny(true);
	}

	public Any toAny(boolean mutable) {
		return Any.create.any(iterable());
	}
	
	public boolean onlySequentialAccess() {
		return true;
	}

	@SuppressWarnings({"unchecked", "rawtypes"})
    public Iterable<? extends SequentialAny> iterable() {
		return new EntriesIterableAdapter(entries());
	}
	
	//TODO: continue!
	public boolean accept(AnyVisitor<SequentialAny> visitor) throws NullPointerException {
		Iterator<? extends Entry<String, ? extends SequentialAny>> it = entries().iterator();
		Entry<String, ? extends SequentialAny> entry = it.next();

		if (it.hasNext()) {
			if (visitor.beginVisit(null, 0, null)) {
				
				
			}
			
			
		} else {
			visitor.visit(entry.getKey(), 0, entry.getValue());
		}
		
		
		
		
		return false;
	}
	
}
